package com.gsit.expenditure.services;

import java.util.List;

import javafx.scene.control.TextField;

import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;

import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

import com.gsit.expenditure.domain.Customer;
import com.gsit.expenditure.domain.Vehicle;
import com.gsit.expenditure.domain.Vendor;

@Repository("vehicleServices")
@Qualifier("vehicleServices")
public class VehicleServices {
	
	@PersistenceContext
	private EntityManager entityManager;
	
	

	@Transactional
	public List<Vehicle> findAll() {
		return entityManager.createNamedQuery("Vehicle.findAll", Vehicle.class).getResultList();
	}
	
	@Transactional
	public List<Vehicle> findAllVehicles(){
		return entityManager.createQuery("select vehicle from Vehicle vehicle").getResultList();
	}
	
	@Transactional
	public <T> T find(Class<T> entityClass, Long id) {
		return entityManager.find(entityClass, id);
	}
	
	@Transactional
	public void saveOrupdate(Vehicle entity){
		
		entityManager.merge(entity);
	}

	
	@Transactional
	public void delete(Vehicle entity) {
		entityManager.remove(entityManager.merge(entity));
	}
	
	
	
	/*@Transactional
	public List<Vehicle> f(Vehicle ) {
		entityManager.merge(entity);
		
	}*/

	

	

}
